package com.example.test.util;

public enum StatusCode { //类要声明公有属性才能在外部包的类中调用
    SUCCESS(200,"请求成功"),
    FAIL(400,"请求失败"),
    SERVER_ERROR(500,"服务失败"),
    NOT_LOGIN(403,"请先登录");

    private int code;

    private String msg;

    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public void setCode(int code){
        this.code = code;
    }

    public void setMsg(String msg){
        this.msg = msg;
    }

    // 普通方法
    public static String getMsg(int code) {
        for (StatusCode s : StatusCode.values()) {
            if (s.getCode() == code) {
                return s.msg;
            }
        }
        return null;
    }

    StatusCode(int code, String msg){
        this.code = code;
        this.msg = msg;
    }


}
